package com.bawei.livedata.net;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import retrofit2.CallAdapter;
import retrofit2.Retrofit;

/**
 * @Author : yaotianxue
 * @Time : On 2023/9/15 08:03
 * @Description : LivaDataCallAdapterFactory
 */
public class LiveDataCallAdapterFactory extends CallAdapter.Factory {
    @Override
    public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
        ParameterizedType parameterizedType = (ParameterizedType) returnType;//转成参数化类型 LiveData<BaseResponseEntity<>>
        Type type = getParameterUpperBound(0, parameterizedType);//获得参数化类型中第一个泛型 BaseResponseEntity
        return new LiveDataCallAdapter<>(type);
    }
}
